package com.cskaoyan.service.wx.zjh;

import com.cskaoyan.mapper.MarketTopicMapper;
import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.pojo.MarketTopic;
import com.cskaoyan.module.pojo.MarketTopicExample;
import com.cskaoyan.module.vo.wx.zjh.WXTopicDetailVO;
import com.cskaoyan.module.vo.wx.zjh.WXTopicListVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/11/17:43
 */

@Service
public class WxTopicServiceImpl implements WxTopicService{
    @Autowired
    MarketTopicMapper topicMapper;
    BaseRespVo baseRespVo = new BaseRespVo();

    @Override
    public BaseRespVo topicList(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);

        MarketTopicExample marketTopicExample = new MarketTopicExample();

        List<MarketTopic> marketTopics = topicMapper.selectByExample(marketTopicExample);

        PageInfo<MarketTopic> pageInfo = new PageInfo<>(marketTopics);

        WXTopicListVO topicListVO = new WXTopicListVO((int) pageInfo.getTotal(), pageInfo.getPages(), pageInfo.getPageSize(), pageInfo.getPageNum(), marketTopics);

        baseRespVo.setData(topicListVO);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");

        return baseRespVo;
    }

    @Override
    public BaseRespVo topicDetail(Integer id) {
        MarketTopic marketTopic = topicMapper.selectByPrimaryKey(id);
        WXTopicDetailVO wxTopicDetailVO = new WXTopicDetailVO();
        wxTopicDetailVO.setTopic(marketTopic);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(wxTopicDetailVO);
        baseRespVo.setErrno(0);
        return baseRespVo;
    }
}
